﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IUserAddressInfoService
    {
        IQueryable<UserAddressInfo> GetUserAddressInfos();
        UserAddressInfo GetUserAddressInfo(int id);
        void CreateUserAddressInfo(UserAddressInfo userAddressInfo);
        void DeleteUserAddressInfo(int id);
        void SaveUserAddressInfo();
    }
    
    public class UserAddressInfoService : IUserAddressInfoService
    {
        private readonly IUserAddressInfoRepository userAddressInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public UserAddressInfoService(IUserAddressInfoRepository userAddressInfoRepository, IUnitOfWork unitOfWork)
        {
            this.userAddressInfoRepository = userAddressInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IUserAddressInfoService Members

        public IQueryable<UserAddressInfo> GetUserAddressInfos()
        {
            var userAddressInfos = userAddressInfoRepository.GetAll();
            return userAddressInfos;
        }

        public UserAddressInfo GetUserAddressInfo(int id)
        {
            var userAddressInfo = userAddressInfoRepository.GetById(id);
            return userAddressInfo;
        }

        public void CreateUserAddressInfo(UserAddressInfo userAddressInfo)
        {
            userAddressInfoRepository.Add(userAddressInfo);
            SaveUserAddressInfo();
        }

        public void DeleteUserAddressInfo(int id)
        {
            var userAddressInfo = userAddressInfoRepository.GetById(id);
            userAddressInfoRepository.Delete(userAddressInfo);
            SaveUserAddressInfo();
        }

        public void SaveUserAddressInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}